//商品管理-商品即秒排期列表
App.util.ns('Admin.Goods.JmThemeGoods');
App.pages.add((function(){
    var NS = Admin.Goods.JmThemeGoods;
    var page = new App.Page({
        name: 'goods/jmthemegoods/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/jmthemegoods',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                //{type: 'keywords'},
                {type: 'timeRange'}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.goods.jmthemegoods.create'},
                {type: 'globe', permission: 'op:admin.goods.jmthemegoods.multiChangeCategory', name: '批量添加', operation: function(dataTable){
                    var win = dataTable.wins.get('categoryManage');
                    win.setTitle('批量添加商品');
                    win.show();
                    win.dataTable.table.frame.find('.chk-row').prop('checked', false).change();
                    //设置按钮
                    win.setBtns([(function(){
                        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
                        cancelBtn.click(function(){
                            win.hide();
                        });
                        return cancelBtn;
                    })(), (function(){
                        var saveBtn = $('<a class="btn btn-success btn-xs">保存</a>');
                        saveBtn.click(function(){
                            var goodsIds = win.dataTable.table.getSelectedIds();
                            var themeIds = dataTable.param.data.theme_id;
                            if(goodsIds.length){
                                dataTable.postData({
                                    url: 'multiChangeCategory',
                                    alert: '保存成功！',
                                    reload: true,
                                    data: {
                                        theme_ids: themeIds,
                                        goods_ids: goodsIds.join(',')
                                    },
                                    after: function(){
                                        win.hide();
                                    }
                                });
                            }else{
                                App.util.hint.alert({
                                    text: '没有选择商品'
                                });
                            }
                        });
                        return saveBtn;
                    })()]);
                }},
                //{parent: 'view', permission: 'op:admin.goods.jmthemegoods.detail'},
                {parent: 'edit', permission: 'op:admin.goods.jmthemegoods.update'},
                {parent: 'drop', permission: 'op:admin.goods.jmthemegoods.delete'},
                {parent: 'multiDrop', permission: 'op:admin.goods.jmthemegoods.multiDelete'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            after: function(dataTable){
                //栏目组织
                dataTable.wins.add(new NS.CategoryManage(dataTable), 'categoryManage');
            },
            dragSort:{
                permission: 'op:admin.goods.jmthemegoods.sort',
                url:'sort',
                filed:'sort'
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
    });
    //页面打开
    page.showStack.add('openPage', function(){
        if(this.params){
            var params = this.params;
            //设置面包屑导航
            this.setBreadcrumb([{
                icon: '<i class="fa fa-crosshairs"></i>',
                content: '商品与专题排期'
            }, {
                content: '商品管理',
                action: function(){
                    App.nav.back();
                }
            }, {
                active: true,
                content: '专题商品管理 - ' + params['jmtheme_name']
            }]);
            //设置参数
            for(var i in params){
                this.dataTable.param.set(i, params[i]);
            }
            if(this.dataTable.paginator){
                this.dataTable.paginator.currentPage = 1;
            }
            //加载数据
            this.dataTable.loadData();
        }
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());